package com.feri.gb.service.impl;

import com.feri.gb.dao.FamilyDao;
import com.feri.gb.entity.Family;
import com.feri.gb.service.intf.FamilyService;
import com.feri.gb.vo.PageBean;
import com.feri.gb.vo.R;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class FamilyServiceImpl implements FamilyService {
@Autowired
private FamilyDao dao;
    @Override
    public R save(Family family) {
        if (dao.add(family)>0){
//            添加成功
            return R.ok();
        }else{
            return R.fail();
        }
    }

    @Override
    public PageBean queryPage(int page, int limit) {
//        分页
        PageHelper.startPage(page,limit);
//           获取分页结果泛型类就是他的返回值数据类型都是Family的
        PageInfo<Family>pageInfo =new PageInfo<>(dao.selectAll());
//返回分页数据
        return PageBean.bean(pageInfo.getTotal(),pageInfo.getList());
    }
}
